// pages/common/notverified/notverified.js
var api = require('../../../config/api.js');
const util = require('../../../utils/util.js');

const app = getApp();
var refreshTimer;

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("not verified onshow");
    this.getVerifyStatusfromServer();
    this.startTimerToGetVerifyStatus();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  getVerifyStatusfromServer: function(){
    let userInfo = wx.getStorageSync('userInfo');
    let that = this;
    console.log("getVerifyStatusfromServer with url: " + api.verifyStatus + ' userInfo.userid ' + userInfo.userid);
    util.request(api.verifyStatus,{
      userId: userInfo.userid
    }).then(function(res){
      console.log("getVerifyStatusfromServer" + JSON.stringify(res));
      var info_temp = res['data'];
      if(info_temp!=null && info_temp!=""){
        console.log("getVerifyStatusfromServer info_temp.status = " + info_temp.status);
        if(info_temp.status == true) {
            that.goStart();
        }
      }
    });
  },

  goStart: function () {
      wx.redirectTo({
        url: "/pages/common/start/start"
      });
  },

  //定时去服务武器拉取审核状态
  startTimerToGetVerifyStatus: function(){
    let that = this;
    refreshTimer = setInterval(that.getVerifyStatusfromServer, 120*1000);
  }
})